package xmlsync2;
import java.io.UnsupportedEncodingException;
import java.sql.Types;
import org.w3c.dom.Document;
import org.w3c.dom.DocumentFragment;


/**
 * @author jinwoo
 *
 * To change this generated comment edit the template variable "typecomment":
 * Window>Preferences>Java>Templates.
 * To enable and disable the creation of type comments go to
 * Window>Preferences>Java>Code Generation.
 */
public class Parameter
{
	String name;
	Object value;
	boolean isrecordset = false;
	short columntype;
	String typename;
	short datatype;
	String encoding = null;
	/**
	 * Constructor Parameter.
	 * @param name
	 * @param columntype
	 * @param datatype
	 * @param typename
	 */
	public Parameter(
		final String name,
		final short columntype,
		final short datatype,
		final String typename,
		final String encoding)
	{
		this.name = name;
		this.datatype = datatype;
		this.encoding = encoding;
		if (datatype == Types.OTHER && typename.equalsIgnoreCase("REF CURSOR"))
			isrecordset = true;
		else isrecordset = false;
		this.columntype = columntype;
		this.typename = typename;
	}


	/**
	 * Method set.
	 * @param object
	 */
	public void set(final Object object)
	{
		if ((datatype == Types.VARCHAR||datatype == Types.LONGVARCHAR) && (this.encoding != null))
		try
		{
			value = new String(((String)object).getBytes(encoding), "EUC-KR");
		}
		catch (UnsupportedEncodingException e)
		{
		}
		else value = object;
	}
	
	public RecordSet getrecordset()
	{
		if (isrecordset)
			return (RecordSet)value;
		else return null;
	}

	/**
	 * Method documentfragment.
	 * @param doc
	 * @param name
	 * @return DocumentFragment
	 */
	public DocumentFragment documentfragment(Document doc, final String name)
	{
		if (isrecordset)
			return ((RecordSet)value).documentfragment(doc, name);
		else return null;
	}

}
